<template>
    <yd-layout>
        <yd-pullrefresh :callback="loadList" v-if="isReady" ref="pullrefresh" :pull-text="$t('message.pullToRefresh')" :drop-text="$t('message.releaseUpdates')" :loading-text="$t('message.refreshIng')">
            <div class="page-index" >
               <!-- 标题 -->
               <div class="page-title">
                   <span> {{ $t('message.caseBidding')}}</span>
                   <lang></lang>
               </div>
               <!-- end -->

               <!-- 竞标项 -->
               <ul class="bidding">
                   <li class="bidding__list" v-for="(list,index) in listData" :key="index">
                       <div class="bidding__status z-notStart" v-if="list.bidding_state == 4"><span class="bidding__status-text" >{{ $t('message.notStart')}}</span></div>
                       <div class="bidding__status z-ing" v-else-if="list.bidding_state == 6"><span class="bidding__status-text" >{{ $t('message.ing')}}</span></div>
                       <div class="bidding__status z-end" v-else-if="list.bidding_state == 7"><span class="bidding__status-text" >{{ $t('message.end')}}</span></div>
                       <div class="bidding--header"> {{ list.case_name }} </div>
                       <div class="bidding__body">
                           <p class="bidding__info">
                               <span class="bidding__info--label">{{ $t('message.CaseNumber')}}：</span>
                               <span class="bidding__info--text">{{ list.case_no }}</span>
                           </p>
                           <p class="bidding__info">
                               <span class="bidding__info--label">{{ $t('message.purchaser')}}：</span>
                               <span class="bidding__info--text">{{ list.buyer_name }}</span>
                           </p>
                           <p class="bidding__info">
                               <span class="bidding__info--label">{{ $t('message.startTime')}}：</span>
                               <span class="bidding__info--text">{{ list.begin_at | timeFormat }}（ {{ list.bidding_area_name }} ）</span>
                           </p>
                       </div>
                       <div class="bidding__footer">
                           <router-link tag="button" :to="{ name: 'detail', params:{id: list.id} }" class="bidding__footer--lookInfo">{{ $t('message.view')}}</router-link>
                           <button
                               type="button"
                               v-if="list.bidding_state == 4 || list.bidding_state == 6"
                               :class="{
                                    'bidding__footer--goBidding': true,
                                    'f-noStart': list.bidding_state == 4
                                }"
                               @click="goBiddingEvent(list)"
                           >{{ $t('message.enter')}}</button>
                       </div>
                   </li>
               </ul>
               <!-- end -->

                <router-link tag="i" class="font_family icon-gerenzhongxin i-goUserInfo" :to="{ name: 'userInfo' }"></router-link>

            </div>
        </yd-pullrefresh>
        <div class="skeleton__index" v-else>
            <div class="skeleton__index-bigTitle"></div>
            <ul class="bidding">
                <li class="bidding__list" v-for="(list,index) in 3" :key="index">
                    <div class="bidding__status"></div>
                    <div class="bidding--header"></div>
                    <div class="bidding__body">
                        <p class="bidding__info speed-1"></p>
                        <p class="bidding__info speed-2"></p>
                        <p class="bidding__info speed-3"></p>
                    </div>
                    <div class="bidding__footer">
                        <div class="bidding__footer-btn"></div>
                        <div class="bidding__footer-btn"></div>
                    </div>
                </li>
            </ul>
        </div>
        <!-- 弹窗信息 -->
        <alert :messagePopup.sync="child_messagePopup"> </alert>
    </yd-layout>
</template>

<script>
    import { api__getList } from "../api";
    import lang from "../components/lang"
    import alert from "../components/alert"

    export default {
        name: "index",
        components:{
            lang, alert
        },
        activated(){
            this.getData()
        },
        data(){
            return {
                // 加载：1加载中 2加载成功 3加载失败
                isReady: false,
                // 请求参数
                reqParams:{
                    pageNum: 1,
                    pageSize: 99
                },
                // 列表数据
                listData: [],
                // 报错弹窗
                child_messagePopup: {
                    isShow: false,
                    type: 'success',
                    title: "标题",
                    text: "描述"
                }
            }
        },
        methods: {
           // 获取数据
            async getData(pull){
                try {
                    let  { data }  = await api__getList(this.reqParams)
                    this.listData = data.case.list
                    this.isReady = true
                    if(pull)  this.$refs.pullrefresh.$emit('ydui.pullrefresh.finishLoad');  // 表示是下拉的时候 才需要关闭
                } catch (err) {
                    this.child_messagePopup = { isShow: true, type: 'error', title: this.$t('message.tips'), text: err.msg }
                }
            },
            // 去往竞标室
            goBiddingEvent(obj){
                if( obj.bidding_state == 6 ){
                    this.$router.push({ name:"room" , params:{ id: obj.id } })
                }else{
                    this.child_messagePopup = { isShow: true, type: 'error', title: this.$t('message.tips'), text: this.$t('message.biddingNotStarted') }
                }
            },
            // 下拉刷新
            loadList(){
                this.getData(true)
            }
        }
    }
</script>
